package com.udian.frame;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;

public class UdianHandlerExceptionResolver implements HandlerExceptionResolver	{
	
	@Override
	public ModelAndView resolveException(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2,
			Exception arg3) {
		 ModelAndView mv = new ModelAndView();  
         /*  使用FastJson提供的FastJsonJsonView视图返回，不需要捕获异常   */  
         FastJsonJsonView view = new FastJsonJsonView();  
         Map<String, Object> attributes = new HashMap<String, Object>();  
         attributes.put("code", "1000001");  
         attributes.put("msg", arg3.getMessage());  
         view.setAttributesMap(attributes);  
         mv.setView(view);   
         //log.debug("异常:" + arg3.getMessage(), arg3);  
         return mv;  
	}

}
